package com.monkey.apipassenger.service;

import com.monkey.apipassenger.remote.ServicePassengerUserClient;
import com.monkey.internalcommon.dto.PassengerUser;
import com.monkey.internalcommon.dto.ResponseResult;
import com.monkey.internalcommon.dto.TokenResult;
import com.monkey.internalcommon.util.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author tao
 * @date 2022/6/22 22:57
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private ServicePassengerUserClient servicePassengerUserClient;

    public ResponseResult getUserByAccessToken(String accessToken) {

        // 解析accessToken, 获取手机号
        log.info("accessToken:" + accessToken);
        TokenResult tokenResult = JwtUtils.checkToken(accessToken);
        String phone = tokenResult.getPhone();
        log.info("phone:" + phone);

        // 根据手机号查询用户信息
        ResponseResult<PassengerUser> userByPhone = servicePassengerUserClient.getUserByPhone(phone);
        return ResponseResult.success(userByPhone.getData());
    }
}
